package com.itheima.product;

import com.itheima.pojo.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  14:47 2020/7/26</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/7/26      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@RestController
public class ProductController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /*
        发送字符串类型消息
     */
    @GetMapping("/sendMsg/{msg}")
    public void sendMsg(@PathVariable String msg) {
        rabbitTemplate.convertAndSend("jiang_li_na", msg);
    }

    /*
        发送对象类型消息
     */
    @GetMapping("/sendUSerMsg")
    public void sendUSerMsg() {
        User user = new User();
        user.setName("朱嘉其");
        user.setAge(18);
        rabbitTemplate.convertAndSend("jiang_li_na", user);
    }
    /*
        发送fanout 广播类型消息
     */
    @GetMapping("sendFanoutMsg/{msg}")
    public void sendFanoutMsg(@PathVariable String msg){
        rabbitTemplate.convertAndSend("fanout_ex", "", msg);
    }

    /*
        发送消息
     */
    @GetMapping("sendDirectMsg/{exchange}/{routingKey}/{msg}")
    public void sendDirectMsg(@PathVariable String exchange,
                              @PathVariable String routingKey,
                              @PathVariable String msg){
        rabbitTemplate.convertAndSend(exchange, routingKey, msg);
    }



}
